<template>
  <div class="tab-control">
    <div
      class="tab-title"
      :class="{ active: index === currentIndex }"
      v-for="(item, index) in titles"
      :key="index"
      @click="itemClick(index)"
    >
      {{ item }}
    </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        currentIndex: 0
      }
    },
    props: {
      titles: {
        type: Array,
        default() {
          return []
        }
      }
    },
    methods: {
      itemClick(index) {
        this.currentIndex = index
        this.$emit('goodsItemClick', index)
      }
    }
  }
</script>

<style scoped>
  .tab-control {
    display: flex;
    justify-content: space-around;
    padding: 8px 0;
    background-color: #fff;
  }
  .tab-title {
    padding: 0 3px;
  }
  .active {
    color: var(--color-tint);
    border-bottom: 2px solid var(--color-tint);
  }
</style>
